var express = require('express')
var winston = require('winston');
var schedule = require('node-schedule');
var moment = require('moment');
var engines = require('consolidate');
var logger = new (winston.Logger)(
		{
			transports : [ new (winston.transports.Console)(
					{
						timestamp : function() {
							return moment().format();
						},
						formatter : function(options) {
							// Return string will be passed to logger.
							return options.timestamp()
									+ ' '
									+ options.level.toUpperCase()
									+ ' '
									+ (undefined !== options.message ? options.message
											: '')
									+ (options.meta
											&& Object.keys(options.meta).length ? '\n\t'
											+ JSON.stringify(options.meta)
											: '');
						}
					}) ]
		});
var app = express();

// mount static files.
app.use('/open', express.static('/Users/Steve/tools/myGit/xNode/public'));

app.get('/', function(req, res) {
	doGetAndPost(req, res);
});

app.post('/', function(req, res) {
	doGetAndPost(req, res);
});

app.listen(8080);

app.engine('html', engines.mustache);
// app.set('view engine', 'html');
app.set('views', __dirname + '/views');
app.locals.email = "nevermissing@vip.qq.com";

// scheduleJobs();

function doGetAndPost(req, res) {
	// res.send('receive get or post here.' + req.query);
	res.render('/app/views/test.html', {
		token : app.locals.email
	});
}

function scheduleJobs() {
	logger.info("schedule job now.");
	var j = schedule.scheduleJob('/5 * * * * *', function() {
		logger.info("hellow world logging test here for str:%s", "test msg.");
	});
}

function loadMustacheTmpls() {
	logger.info('loading tmpl start.');
	logger.info('loading tmpl finish.');
}
